package situ.autoweter.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import situ.autoweter.entity.IvInvoice;
import situ.autoweter.service.PyPayService;
import situ.autoweter.entity.PyPay;

import java.beans.PropertyEditor;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * PyPay的路由接口服务
 * 
 * @author 胡文
 *
 */
@Controller
public class PyPayController {

	/** PyPayService服务 */
	@Autowired
	private PyPayService pyPayService;


	
	/**
	 * 查询所有PyPay数据的方法
	 * @param value
	 * @return
	 */
	@RequestMapping(value = "queryPyPay", produces = {"application/json;charset=UTF-8"})
	public String find(PyPay value,Map map) {
		 List<PyPay> list= pyPayService.find(value);
         map.put("items",list);
         return "页面名称自己改";
	}
	
	/**
	 * 通过id查询PyPay数据的方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "queryPyPayById/{id}", produces = {"application/json;charset=UTF-8"})
	public String findOne(@PathVariable(name="id") String id,Map map) {
        PyPay obj=  pyPayService.findOne(id);
        map.put("PyPay",obj);
        return "页面名称自己改";
	}
	
	/**
	 * 插入PyPay属性不为空的数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "savePyPay", produces = {"application/json;charset=UTF-8"})
	public String save(PyPay value) {
		  pyPayService.saveNotNull(value);
        return "redirect:/queryPyPay";
	}
	
	/**
	 * 更新PyPay属性不为空的数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "updatePyPay", produces = {"application/json;charset=UTF-8"})
	public String update(PyPay value) {
		  pyPayService.updateNotNullById(value);
          return "redirect:/queryPyPay";
	}
	
	/**
	 * 通过id删除PyPay数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "delPyPayById/{id}", produces = {"application/json;charset=UTF-8"})
	public String delete(@PathVariable(name="id") String id) {
		  pyPayService.deleteById(id);
          return "redirect:/queryPyPay";
	}


	//易芷若
	//收费情况报表全查
	@RequestMapping(value = "querymoney", produces = {"application/json;charset=UTF-8"})
	public String querymoney(Map map) {
		List<Map> list= pyPayService.querymoney();
		PyPay py=pyPayService.moneyAll();
		List<Map> SF=pyPayService.querySF();
		map.put("items",list);
		map.put("itemsPy", py);
		map.put("itemsSF", SF);
		return "page/pay_reportPay";
	}
	//根据编码和收费人员查
	@RequestMapping(value = "querybyBM", produces = {"application/json;charset=UTF-8"})
	public String querybyBM(Map map,@RequestParam(value = "userno")String userno,@RequestParam(value = "medium")String medium){
		List<Map> list=pyPayService.querybyBM(userno==""?"%%":userno,medium==""?"%%":medium);
		PyPay py=pyPayService.moneyAll();
		List<Map> SF=pyPayService.querySF();
		map.put("items", list);
		map.put("itemsPy", py);
		map.put("itemsSF", SF);
		map.put("userno", userno);
		map.put("medium", medium);

		return "page/pay_reportPay";
	}
//刘旻的东西
@InitBinder  //
public void dateconvert(WebDataBinder bind){
	DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
	PropertyEditor n=new CustomDateEditor(format, true);
	bind.registerCustomEditor(Date.class, n);

}



	@RequestMapping(value = "ShowAll", produces = {"application/json;charset=UTF-8"})
	public String ShowAll(Map map){
		List<Map> list=pyPayService.showAll();
		map.put("list", list);
		return "page/pay_invoiceReprint.html";
	}
	@RequestMapping(value = "UpType", produces = {"application/json;charset=UTF-8"})
	public String UpType(Map map,@RequestParam(value = "ID") Integer[] ID){
		pyPayService.Update(ID);
		return this.ShowAll(map);
	}
	@RequestMapping(value = "find")
	public String find(Map map,IvInvoice ivInvoice){
		List<Map> list=pyPayService.find(ivInvoice);
		map.put("list", list);
		return "page/pay_invoiceReprint.html";
	}
}

